import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import Main from '../views/Main.vue'
import Article from '../views/Article.vue'
import Hero from '../views/Hero.vue'
//import 404 from '../views/404.vue'
import HeroList from '../views/HeroList.vue'

Vue.use(VueRouter)

const routes = [{
    path: '/',
    name: 'main',
    component: Main,
    children: [{
        path: '/',
        name: "Home",
        component: Home
      },
      {
        path: '/articles/:id',
        name: 'article',
        component: Article,
        props: true
      },
      //{path:'/heroes',name:'hero',component:Hero,props:true},
    ]
  },
  {
    path: '/heroes/:id',
    name: 'hero',
    component: Hero,
    props: true
  },
  {
    path: '/heroes/skins/:id',
    name: 'heroskinlist',
    component: HeroList,
    props: true
  },
  {
    path:'*',
    component:()=>import('@/views/404')
  }
]

const router = new VueRouter({
  routes
})
router.beforeEach((to,from,next)=>{
  if (to.matched.length!==0) {
    next()
  } else {
    next({path:'/404'})
  }
})
export default router